<?php

/**
 * @author 
 * @copyright 2008
 */
include("settings.php");
//TODO: $obj_id
$obj_id = 0;
if(isset($_REQUEST['obj_id']) and intval($_REQUEST['obj_id']) != 0)
{
	$obj_id = intval($_REQUEST['obj_id']);
}
//TODO: $p - parent
/** parent */
$p = 0;
if(isset($_REQUEST['p']))
{
	$p = intval($_REQUEST['p']);
}
//TODO: $do
$do = '';
if(isset($_REQUEST['do']) and strval($_REQUEST['do']) != '')
{
	$do = strval($_REQUEST['do']);
	unset($_REQUEST['do']);
}
//TODO: Doing Item
if(file_exists(ADMIN_DIR.MOD_DIR.$this->dir.'/item.'.$do.MOD_EXT))
{
	include_once(ADMIN_DIR.MOD_DIR.$this->dir.'/item.'.$do.MOD_EXT);
}
//TODO: Items
$items=$this->getSubFor($p);
if($items!=false)
{
	$smarty->assign("items",$items);
}

//TODO: Item
if($obj_id != 0)
{
	$item = $this->getPage($obj_id);
	if($item != false)
	{
		$smarty->assign("item",$item);
		$p = intval($item['pid']);
		$do = 'edit';
	}
	else
	{
		$_SESSION['message'] = "Выбранного объекта нет в базе данных.";
		$do = 'none';
	}
}
elseif(isset($_SESSION['try_to_edit_item']))
{
	$smarty->assign("item",$_SESSION['try_to_edit_item']);
	unset($_SESSION['try_to_edit_item']);
	$do = 'edit';
}
elseif(isset($_SESSION['try_to_add_item']))
{
	$smarty->assign("item",$_SESSION['try_to_add_item']);
	unset($_SESSION['try_to_add_item']);
	$do = 'add';
}
else
{
	$do = 'add';
}
//TODO: System messages
if(isset($_SESSION['message']) and strval($_SESSION['message']) != '')
{
	$smarty->assign("message",strval($_SESSION['message']));
	unset($_SESSION['message']);
}
//TODO: Local Error messages
if(isset($_SESSION['error_message']) and !empty($_SESSION['error_message']))
{
	$smarty->assign("error_message",$_SESSION['error_message']);
	unset($_SESSION['error_message']);
}
//TODO: Local Success messages
if(isset($_SESSION['success_message']) and !empty($_SESSION['success_message']))
{
	$smarty->assign("success_message",strval($_SESSION['success_message']));
	unset($_SESSION['success_message']);
}
//TODO: Адресная строка
$this->adress_string = array();
$this->adress_string[] = array(
	'title' =>"Главная",
	'menu_title' =>"Главная",
	'alias' => ADMIN_URL.'/'.$this->full_alias
);
if($p != 0)
{
	$parents = $this->getParents($p);
	foreach($parents as $k=>$v)
	{
		$this->adress_string[] = array(
			'title' =>$v['title'],
			'menu_title' =>$v['menu_title'],
			'alias' => ADMIN_URL.'/'.$this->full_alias.(intval($v['id']) != 0 ? "?p=".intval($v['id']) : '')
		);
	}
}
//TODO: $smarty->assign
$smarty->assign("do",$do);
$smarty->assign("obj_id",$obj_id);
$smarty->assign("p",$p);
?>